<?php
namespace Admin\Behaviors;

use Think\Behavior;
use Common\Model\Common\SysLogModel;

class LogBehavior extends Behavior
{
    public function run(&$params)
    {
        //$this->manageLog();
    }

    public function manageLog()
    {
        //判断是否记录
        if(C('SAVE_LOG'))
        {
            //过滤掉的控制器列表
            $filter_list = array(
                'Index',
                'Upload',
                'Home',
                'Area',
                'Auth',
            );
            if(ACTION_NAME == '' || strchr(ACTION_NAME,'auth') ||  in_array(CONTROLLER_NAME, $filter_list) ) {
                return;
            }else {
                $data = array('GET'=>$_GET);
                if(IS_POST){ $data['POST'] = $_POST; }
                if(count($_POST) > 0  || count($_POST) > 0 ){
                    $data_json = json_encode($data);
                    $log_db = new SysLogModel();
                    $log_db->addSysLog(array(
                        'member_id'    => cdSession('member_id'),
                        'member_name'  => cdSession('real_name'),
                        'controller'   => CONTROLLER_NAME,
                        'action'       => ACTION_NAME,
                        'queryString'  => $data_json,
                        'time'         => date('Y-m-d H-i-s'),
                        'ip'           => get_client_ip(),
                    ));
                }else{
                    return;
                }
            }
        }
    }
}